home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / 606+gest.cpt / Sound.p < prev    next >
Text File  |  1990-10-17  |  14KB  |  503 lines

  1. {    This file has been processed by The THINK Pascal Source Converter, v1.1.    }
  2. {}
  3. {    Copyright © Symantec Corporation 1990}
  4. {    Copyright Apple Computer, Inc. 1985-1990}
  5. {    All rights reserved.}
  6. {}
  7. {    6.0.6 Sound interface}
  8. {}
  9. {    Converted from the 6.0.6  beta 19 interfaces  10/17/90  -MYG}
  10.  
  11.  
  12. unit Sound;
  13. interface
  14.  
  15.  
  16.     const
  17.         synthCodeRsrc = 'snth';
  18.         soundListRsrc = 'snd ';
  19.  
  20. { synthesizer numbers for SndNewChannel }
  21.  
  22.         noteSynth = 1;            {note synthesizer}
  23.         waveTableSynth = 3;             {wave table synthesizer}
  24.         sampledSynth = 5;            {sampled sound synthesizer}
  25.  
  26. { Param2 values }
  27.  
  28.         twelthRootTwo = 1.05946309434;
  29.         infiniteTime = $7FFFFFFF;
  30.  
  31. { command numbers for SndDoCommand }
  32.  
  33.         nullCmd = 0;
  34.         initCmd = 1;
  35.         freeCmd = 2;
  36.         quietCmd = 3;
  37.         flushCmd = 4;
  38.         reInitCmd = 5;
  39.  
  40.         waitCmd = 10;
  41.         pauseCmd = 11;
  42.         resumeCmd = 12;
  43.         callBackCmd = 13;
  44.         syncCmd = 14;
  45.         emptyCmd = 15;
  46.  
  47.         tickleCmd = 20;
  48.         requestNextCmd = 21;
  49.         howOftenCmd = 22;
  50.         wakeUpCmd = 23;
  51.         availableCmd = 24;
  52.         versionCmd = 25;
  53.         totalLoadCmd = 26;
  54.         loadCmd = 27;
  55.  
  56.         scaleCmd = 30;
  57.         tempoCmd = 31;
  58.  
  59.         noteCmd = 40;
  60.         restCmd = 41;
  61.         freqCmd = 42;
  62.         ampCmd = 43;
  63.         timbreCmd = 44;
  64.  
  65.         waveTableCmd = 60;
  66.         phaseCmd = 61;
  67.  
  68.         soundCmd = 80;
  69.         bufferCmd = 81;
  70.         rateCmd = 82;
  71.         continueCmd = 83;
  72.         doubleBufferCmd = 84;
  73.         getRateCmd = 85;
  74.  
  75.         sizeCmd = 90;
  76.         convertCmd = 91;
  77.  
  78.         stdQLength = 128;
  79.         dataPointerFlag = $8000;
  80.  
  81.         waveInitChannelMask = 7;
  82.         waveInitChannel0 = 4;            {channel 0 - wave table only}
  83.         waveInitChannel1 = 5;            {channel 1 - wave table only}
  84.         waveInitChannel2 = 6;            {channel 2 - wave table only}
  85.         waveInitChannel3 = 7;            {channel 3 - wave table only}
  86.  
  87.         initSRateMask = 48;
  88.         initStereoMask = 192;
  89.         initChanLeft = 2;               {left stereo channel }
  90.         initChanRight = 3;              {right stereo channel}
  91.         initSRate22k = 32;              {22k sampling rate}
  92.         initMono = 128;          {monophonic channel}
  93.         initStereo = 192;          {stereo channel}
  94.         initNoInterp = 4;
  95.         initNoSRC = 8;
  96.         initNoMultiChannel = 4096;
  97.         initMACE3 = 768;
  98.         initMACE6 = 1024;
  99.  
  100.         stdSH = $00;
  101.         extSH = $FF;
  102.         cmpSH = $FE;
  103.         notCompressed = 0;
  104.         twoToOne = 1;
  105.         eightToThree = 2;
  106.         threeToOne = 3;
  107.         sixToOne = 4;
  108.         outsideCmpSH = 0;
  109.         insideCmpSH = 1;
  110.         aceSuccess = 0;
  111.         aceMemFull = 1;
  112.         aceNilBlock = 2;
  113.         aceBadComp = 3;
  114.         aceBadEncode = 4;
  115.         aceBadDest = 5;
  116.         aceBadCmd = 6;
  117.         sixToOnePacketSize = 8;
  118.         threeToOnePacketSize = 16;
  119.         stateBlockSize = 64;
  120.         stateBlockSizeMinusOne = Stateblocksize - 1;
  121.         leftOverBlockSize = 32;
  122.         leftOverBlockSizeMinusOne = LeftOverBlockSize - 1;
  123.  
  124.         firstSoundFormat = 1;
  125.         secondSoundFormat = 2;
  126.  
  127.         sysBeepDisable = $0000;
  128.         sysBeepEnable = $0001;
  129.  
  130.                                         { unitTypes for AudioSelection.unitType }
  131.         unitTypeNoSelection = $FFFF;
  132.         unitTypeSeconds = $0000;
  133.  
  134.  
  135.         dbBufferEmpty = $00000000;
  136.         dbBufferEmptyMask = $FFFFFFFE;
  137.         dbBufferReady = $00000001;
  138.         dbBufferExhausted = $00000002;
  139.         dbLastBuffer = $00000004;
  140.  
  141. { errors codes for Sound Manager 7.0 }
  142.         notEnoughBufferSpace = -207;            { could not allocate enough memory }
  143.         badFileFormat = -208;            { was not type AIFF or was of bad format,corrupt }
  144.         channelBusy = -209;            { the Channel is being used for a PFD already }
  145.         buffersTooSmall = -210;            { can not operate in the memory allowed }
  146.         channelNotBusy = -211;
  147.         noMoreRealTime = -212;            { not enought CPU cycles left to add another task }
  148.         badParam = -213;            { invalid argument }
  149.  
  150. { constants for MACE in the dispatcher }
  151.         MACEToolNum = 16;
  152.         sMgrMACEVersion = 0;
  153.         sMgrComp3to1 = 4;
  154.         sMgrExp1to3 = 8;
  155.         sMgrComp6to1 = 12;
  156.         sMgrExp1to6 = 16;
  157.  
  158. { constants for Sound Manager Extensions in the dispatcher }
  159.         sMgrToolNum = 8;
  160.         sMgrSndStartFilePlay = (13 * 256) + 0;
  161.         sMgrSndPauseFilePlay = (2 * 256) + 4;
  162.         sMgrSndStopFilePlay = (3 * 256) + 8;
  163.         sMgrSndSoundManagerVersion = 12;
  164.         sMgrSndChannelStatus = 16;
  165.         sMgrSndManagerStatus = 20;
  166.         sMgrSndGetSysBeepState = 24;
  167.         sMgrSndSetSysBeepState = 28;
  168.         sMgrSndPlayDoubleBuffer = 32;
  169.         sMgrSndGetBufferStufferLoad = 36;
  170.         sMgrSndGetMixerLoad = 40;
  171.  
  172.  
  173.     type
  174.  
  175.  
  176.         FreeWave = packed array[0..30000] of Byte;
  177.  
  178.         FFSynthPtr = ^FFSynthRec;
  179.         FFSynthRec = record
  180.                 mode: INTEGER;
  181.                 count: Fixed;
  182.                 waveBytes: FreeWave;
  183.             end;
  184.  
  185.         Tone = record
  186.                 count: INTEGER;
  187.                 amplitude: INTEGER;
  188.                 duration: INTEGER;
  189.             end;
  190.  
  191.         Tones = array[0..5000] of Tone;
  192.  
  193.         SWSynthPtr = ^SWSynthRec;
  194.         SWSynthRec = record
  195.                 mode: INTEGER;
  196.                 triplets: Tones;
  197.             end;
  198.  
  199.         Wave = packed array[0..255] of Byte;
  200.  
  201.         WavePtr = ^Wave;
  202.  
  203.         FTSndRecPtr = ^FTSoundRec;
  204.         FTSoundRec = record
  205.                 duration: INTEGER;
  206.                 sound1Rate: Fixed;
  207.                 sound1Phase: LONGINT;
  208.                 sound2Rate: Fixed;
  209.                 sound2Phase: LONGINT;
  210.                 sound3Rate: Fixed;
  211.                 sound3Phase: LONGINT;
  212.                 sound4Rate: Fixed;
  213.                 sound4Phase: LONGINT;
  214.                 sound1Wave: WavePtr;
  215.                 sound2Wave: WavePtr;
  216.                 sound3Wave: WavePtr;
  217.                 sound4Wave: WavePtr;
  218.             end;
  219.  
  220.         FTSynthPtr = ^FTSynthRec;
  221.         FTSynthRec = record
  222.                 mode: INTEGER;
  223.                 sndRec: FTSndRecPtr;
  224.             end;
  225.  
  226.         SndCommand = packed record
  227.                 cmd: INTEGER;
  228.                 param1: INTEGER;
  229.                 param2: LONGINT;
  230.             end;
  231.  
  232.         Time = LONGINT;
  233.  
  234.         ModifierStubPtr = ^ModifierStub;
  235.         ModifierStub = packed record
  236.                 nextStub: ModifierStubPtr;
  237.                 code: ProcPtr;
  238.                 userInfo: LONGINT;
  239.                 count: Time;
  240.                 every: Time;
  241.                 flags: SignedByte;
  242.                 hState: SignedByte;
  243.             end;
  244.  
  245.         SndChannelPtr = ^SndChannel;
  246.         SndChannel = packed record
  247.                 nextChan: SndChannelPtr;
  248.                 firstMod: ModifierStubPtr;
  249.                 callBack: ProcPtr;
  250.                 userInfo: LONGINT;
  251.                 wait: Time;                 {The following is for internal Sound Manager use only.}
  252.                 cmdInProgress: SndCommand;
  253.                 flags: INTEGER;
  254.                 qLength: INTEGER;
  255.                 qHead: INTEGER;                 {next spot to read or -1 if empty}
  256.                 qTail: INTEGER;                 {next spot to write = qHead if full}
  257.                 queue: array[0..127] of SndCommand;
  258.             end;
  259.  
  260.         SoundHeaderPtr = ^SoundHeader;
  261.         SoundHeader = packed record
  262.                 samplePtr: Ptr;                       {if NIL then samples are in sampleArea}
  263.                 length: LONGINT;
  264.                 sampleRate: Fixed;
  265.                 loopStart: LONGINT;
  266.                 loopEnd: LONGINT;
  267.                 encode: Byte;
  268.                 baseNote: Byte;
  269.                 sampleArea: array[0..0] of Byte;
  270.             end;
  271.  
  272.         ModRef = record
  273.                 modNumber: INTEGER;
  274.                 modInit: LONGINT;
  275.             end;
  276.  
  277.  
  278.                     {    •••   MACE typedef structures    •••   }
  279.  
  280.         StateBlockPtr = ^StateBlock;
  281.         StateBlock = record
  282.                 stateVar: array[0..stateBlockSizeMinusOne] of INTEGER;
  283.             end;
  284.  
  285.         LeftOverBlockPtr = ^LeftOverBlock;
  286.         LeftOverBlock = record
  287.                 count: INTEGER;
  288.                 sampleArea: array[0..leftOverBlockSizeMinusOne] of INTEGER;
  289.             end;
  290.  
  291.         CmpSoundHeaderPtr = ^CmpSoundHeader;
  292.         CmpSoundHeader = packed record
  293.                 samplePtr: Ptr;                           {if NIL then samples are in sampleArea}
  294.                 numChannels: LONGINT;                    { AIFC, number of channels  mono = 1 }
  295.                 sampleRate: Fixed;                    { sample rate in Apples Fixed point representation }
  296.                 loopStart: LONGINT;                    { loopStart of sound before compression }
  297.                 loopEnd: LONGINT;                    { loopEnd of sound before compression }
  298.                 encode: Byte;                        { data structure used ,  stdSH, extSH, or cmpSH }
  299.                 baseNote: Byte;                        { same meaning as regular SoundHeader }
  300.                 numSampleFrames: LONGINT;                    { length in frames    ( packetFrames or sampleFrames }
  301.                 AIFFSampleRate: EXTENDED;                    { AIFC, IEEE sample rate }
  302.                 MarkerChunk: Ptr;                        { AIFC, sync track }
  303.                 FutureUse1: Ptr;                        { reserved by Apple }
  304.                 FutureUse2: Ptr;                        { reserved by Apple }
  305.                 StateVars: StateBlockPtr;            { pointer to State Block }
  306.                 LeftOverSamples: LeftOverBlockPtr;            { used to save truncated samples between compression calls }
  307.                 compressionID: INTEGER;                    { 0 means no compression, non zero means compressionID }
  308.                 packetSize: INTEGER;                    { AIFC, number of bits in compressed sample packet }
  309.                 snthID: INTEGER;                    { Resource ID of Sound Manager snth that contains NRT C/E }
  310.                 sampleSize: INTEGER;                    { AIFC, number of bits in non-compressed sample }
  311.                 sampleArea: array[0..0] of Byte;    { space for when samples follow directly }
  312.             end;
  313.  
  314.         ExtSoundHeaderPtr = ^ExtSoundHeader;
  315.         ExtSoundHeader = packed record
  316.                 samplePtr: Ptr;                           {if NIL then samples are in sampleArea}
  317.                 numChannels: LONGINT;                    { AIFF, number of channels  mono = 1 }
  318.                 sampleRate: Fixed;                    { sample rate in Apples Fixed point representation }
  319.                 loopStart: LONGINT;                    { loopStart of sound before compression }
  320.                 loopEnd: LONGINT;                    { loopEnd of sound before compression }
  321.                 encode: Byte;                        { data structure used ,  stdSH, extSH, or cmpSH }
  322.                 baseNote: Byte;                        { same meaning as regular SoundHeader }
  323.                 numSampleFrames: LONGINT;                    { length in total number of frames }
  324.                 AIFFSampleRate: EXTENDED;                    { AIFF, IEEE sample rate }
  325.                 MarkerChunk: Ptr;                        { AIFF, sync track }
  326.                 InstrumentChunks: Ptr;
  327.                 AESRecording: Ptr;
  328.                 sampleSize: INTEGER;                    { AIFF, number of bits in sample }
  329.                 FutureUse1: INTEGER;                    { reserved by Apple }
  330.                 FutureUse2: LONGINT;                    { reserved by Apple }
  331.                 FutureUse3: LONGINT;                    { reserved by Apple }
  332.                 FutureUse4: LONGINT;                    { reserved by Apple }
  333.                 sampleArea: array[0..0] of Byte;    { space for when samples follow directly }
  334.             end;
  335.  
  336.  
  337.  
  338.         SMStatusPtr = ^SMStatus;
  339.         SMStatus = record
  340.                 smMaxCPULoad: INTEGER;
  341.                 smNumChannels: INTEGER;
  342.                 smCurCPULoad: INTEGER;
  343.             end;
  344.  
  345.         SCStatusPtr = ^SCStatus;
  346.         SCStatus = record
  347.                 scStartTime: Fixed;
  348.                 scEndTime: Fixed;
  349.                 scCurrentTime: Fixed;
  350.                 scChannelBusy: BOOLEAN;
  351.                 scChannelDisposed: BOOLEAN;
  352.                 scChannelPaused: BOOLEAN;
  353.                 scUnused: INTEGER;
  354.                 scChannelAttributes: LONGINT;
  355.                 scCPULoad: LONGINT;
  356.             end;
  357.  
  358.         SndDoubleBufferPtr = ^SndDoubleBuffer;
  359.         SndDoubleBuffer = record
  360.                 dbNumFrames: LONGINT;
  361.                 dbFlags: LONGINT;
  362.                 dbUserInfo: array[0..1] of LONGINT;
  363.                 dbSoundData: array[0..0] of INTEGER;
  364.             end;
  365.  
  366.         AudioSelectionPtr = ^AudioSelection;
  367.         AudioSelection = record
  368.                 unitType: LONGINT;
  369.                 selStart: Fixed;
  370.                 selEnd: Fixed;
  371.             end;
  372.  
  373.         SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  374.         SndDoubleBufferHeader = record
  375.                 dbhNumChannels: INTEGER;
  376.                 dbhSampleSize: INTEGER;
  377.                 dbhCompressionID: INTEGER;
  378.                 dbhPacketSize: INTEGER;
  379.                 dbhBufferPtr: array[0..1] of SndDoubleBufferPtr;
  380.                 dbhDoubleBack: ProcPtr;
  381.             end;
  382.  
  383.         SndListPtr = ^SndListResource;
  384.         SndListResource = record
  385.                 format: INTEGER;
  386.                 numModifiers: INTEGER;
  387.                 modifierPart: array[0..0] of ModRef;
  388.                 numCommands: INTEGER;
  389.                 commandPart: array[0..0] of SndCommand;
  390.                 dataPart: packed array[0..0] of Byte;
  391.             end;
  392.  
  393.  
  394.  
  395.  
  396.                     {    •••   Trap Call Definitions    •••   }
  397.  
  398.  
  399.     function SndDoCommand (chan: SndChannelPtr; cmd: SndCommand; noWait: BOOLEAN): OSErr;
  400.     inline
  401.         $A803;
  402.     function SndDoImmediate (chan: SndChannelPtr; cmd: SndCommand): OSErr;
  403.     inline
  404.         $A804;
  405.     function SndNewChannel (var chan: SndChannelPtr; synth: INTEGER; init: LONGINT; userRoutine: ProcPtr): OSErr;
  406.     inline
  407.         $A807;
  408.     function SndDisposeChannel (chan: SndChannelPtr; quietNow: BOOLEAN): OSErr;
  409.     inline
  410.         $A801;
  411.     function SndPlay (chan: SndChannelPtr; sndHdl: Handle; async: BOOLEAN): OSErr;
  412.     inline
  413.         $A805;
  414.     function SndControl (id: INTEGER; var cmd: SndCommand): OSErr;
  415.     inline
  416.         $A806;
  417.  
  418.     procedure SetSoundVol (level: INTEGER);
  419.     procedure GetSoundVol (var level: INTEGER);
  420.     procedure StartSound (synthRec: Ptr; numBytes: LONGINT; completionRtn: ProcPtr);
  421.     procedure StopSound;
  422.     function SoundDone: BOOLEAN;
  423.     function SndAddModifier (chan: SndChannelPtr; modifier: ProcPtr; id: INTEGER; init: LONGINT): OSErr;
  424.     inline
  425.         $A802;
  426.  
  427.  
  428. {    Sound Manager Extension calls - a future Glue Library will replace these    }
  429.  
  430.  
  431.     function SndSoundManagerVersion: LONGINT;
  432.     inline
  433.         $203C, sMgrSndSoundManagerVersion, sMgrToolNum, $A800;
  434.  
  435.     function SndStartFilePlay (theChannel: SndChannelPtr; fRefNum: INTEGER; resNum: INTEGER; totalSpace: LONGINT; TheBuffer: Ptr; theSelection: AudioSelectionPtr; completionRtn: ProcPtr; async: BOOLEAN): OSErr;
  436.     inline
  437.         $203C, sMgrSndStartFilePlay, sMgrToolNum, $A800;
  438.  
  439.     function SndPauseFilePlay (theChannel: SndChannelPtr): OSErr;
  440.     inline
  441.         $203C, sMgrSndPauseFilePlay, sMgrToolNum, $A800;
  442.  
  443.     function SndStopFilePlay (theChannel: SndChannelPtr; async: BOOLEAN): OSErr;
  444.     inline
  445.         $203C, sMgrSndStopFilePlay, sMgrToolNum, $A800;
  446.  
  447.     function SndChannelStatus (theChannel: SndChannelPtr; theLength: INTEGER; theStatus: SCStatusPtr): OSErr;
  448.     inline
  449.         $203C, sMgrSndChannelStatus, sMgrToolNum, $A800;
  450.  
  451.     function SndManagerStatus (theLength: INTEGER; theStatus: SCStatusPtr): OSErr;
  452.     inline
  453.         $203C, sMgrSndManagerStatus, sMgrToolNum, $A800;
  454.  
  455.     function SndGetSysBeepState (var sysBeepState: INTEGER): OSErr;
  456.     inline
  457.         $203C, sMgrSndGetSysBeepState, sMgrToolNum, $A800;
  458.  
  459.     function SndSetSysBeepState (sysBeepState: INTEGER): OSErr;
  460.     inline
  461.         $203C, sMgrSndSetSysBeepState, sMgrToolNum, $A800;
  462.  
  463.     function SndPlayDoubleBuffer (theChannel: SndChannelPtr; theParams: SndDoubleBufferHeaderPtr): OSErr;
  464.     inline
  465.         $203C, sMgrSndPlayDoubleBuffer, sMgrToolNum, $A800;
  466.  
  467.     function SndGetBufferStufferLoad (channelFeatures: INTEGER): INTEGER;
  468.     inline
  469.         $203C, sMgrSndGetBufferStufferLoad, sMgrToolNum, $A800;
  470.  
  471.     function SndGetMixerLoad (numChannels: INTEGER): INTEGER;
  472.     inline
  473.         $203C, sMgrSndGetMixerLoad, sMgrToolNum, $A800;
  474.  
  475.  
  476.     function MACEVersion: LONGINT;
  477.     inline
  478.         $203C, sMgrMACEVersion, MACEToolNum, $A800;
  479.  
  480.     procedure Comp3to1 (inBuffer: Ptr; outBuffer: Ptr; Cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  481.     inline
  482.         $203C, sMgrComp3to1, MACEToolNum, $A800;
  483.  
  484.     procedure Comp6to1 (inBuffer: Ptr; outBuffer: Ptr; Cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  485.     inline
  486.         $203C, sMgrComp6to1, MACEToolNum, $A800;
  487.  
  488.     procedure Exp1to3 (inBuffer: Ptr; outBuffer: Ptr; Cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  489.     inline
  490.         $203C, sMgrExp1to3, MACEToolNum, $A800;
  491.  
  492.     procedure Exp1to6 (inBuffer: Ptr; outBuffer: Ptr; Cnt: LONGINT; inState: Ptr; outState: Ptr; numChannels: LONGINT; whichChannel: LONGINT);
  493.     inline
  494.         $203C, sMgrExp1to6, MACEToolNum, $A800;
  495.  
  496.  
  497.  
  498.     { UsingSound }
  499.  
  500.  
  501. implementation
  502. end.
  503.